package com.android.pagemarket.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.android.pagemarket.R;
import com.android.pagemarket.business.model.Adv;
import com.android.pagemarket.ui.activity.setting.VideoShowActivity;
import com.android.pagemarket.util.ImageLoader;
import com.android.pagemarket.util.ImageLoader.Imager;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-8-21
 * @see : 广告图片
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class AdvView extends ImageView implements OnClickListener
{
    private Adv mData;
     
    public AdvView(Context context)
    {
        super(context);
    }
   
    public AdvView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
   
    public void bindData(Adv data)
    {
        this.mData = data;
        setOnClickListener(this);
        if(mData.imgRid == 0)
        {
            int size = getResources().getDimensionPixelSize(R.dimen.flow_adv_height);
            ImageLoader.getInstance().DisplayImage(new Imager(mData.advImgUrl, this, size, R.drawable.ic_launcher));
        }else
        {
            setImageResource(mData.imgRid);
        }
    }
    
    @Override
    public void onClick(View v)
    {
       if(mData.advType == 0)
       {
           ImagePopWindow popWin = new ImagePopWindow(getContext());
           if(mData.imgRid == 0)
           {          
               popWin.setImageUrl(mData.advImgUrl);
           }else
           {
               popWin.setImageResource(mData.imgRid);
           }
           popWin.showAtLocation(getRootView(), Gravity.CENTER, 0, 0);
       }else
       {
           VideoShowActivity.startActivity(getContext());
       }
    }
}